#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>

#define filename "log.txt"

int main()
{
  close(1);
  int fd = open(filename, O_CREAT|O_WRONLY|O_TRUNC, 0666);
  if (fd < 0)
  {
    perror("open");
    return 1;
  }
  //printf("fd: %d\n", fd);

  const char *msg = "hello Linux\n";
  int cnt = 5;
  while (cnt)
  {
    write(1, msg, strlen(msg));
    cnt--;
  }

  close(fd);


  return 0;
}
